<?php
$page_title = 'eTAT| Preview';
$access_level = 1;
$script = 'survey';


 
require_once '../../controller.php';
require_once '../../classes/Survey.php';
require_once '../../classes/Question.php';
require_once '../../header.php';
?>
<script type="text/javascript">
function change(sid,sec,num){
    var sid = sid
    var sec = sec
    var num = num
	window.location ="preview.php?sid="+sid+"&sec="+sec+"&num="+num;
}
</script>

<?php 

if(isset($_REQUEST['sid'])){
	$survey_id = $_REQUEST['sid'];
}

if(isset($_REQUEST['sec'])){
	$sec = $_REQUEST['sec'];
}

if(isset($_REQUEST['num'])){
	$q_num = $_REQUEST['num'];
}

$s = new Survey();
$q = new Question();

$survey = $s->getSurvey($survey_id);
echo "<a href='question.php?sid=$survey_id'>Go Back to Questions</a><br>"; 
echo '<div id="preview">';
echo "<h1 align='center'>".$survey['title']."</h1>";
if($sec==1){
echo "<p align='center'>".$survey['welcome_message']."</p>";
}
echo '<br><br>';
echo '( Questions marked <font color="red" size="5">*</font> are required )<br><br>';

$questions = $s->getQuestions($survey_id);
if($questions){
	$size = sizeof($questions);
	$num = $q_num-$sec+2;
	foreach($questions as $i=>$value){
		
		$type = $value->type;
		$required = $value->required;
		$question = $value->question;
		$create_section = $value->create_section;
		$order = $value->order;
		$response1 = $value->response1;
		$response2 = $value->response2;
		$response3 = $value->response3;
		$response4 = $value->response4;
		$response5 = $value->response5;
		$response6 = $value->response6;
		
		if($q_num<$i || $q_num==$i){
		if($create_section =="Y" && $i!=$q_num){
			$sec++ ;$q_num=$i;
			if($sec>2){
			echo "<div id='back'><input type='button' onclick='history.go(-1)' Value='Back'></div>";
			}
			echo "<div id='next'><input type='submit' value='next' onclick='change($survey_id,$sec,$q_num)'></div>";
			break;
			
			//echo '<p align = "center">=====================================================New Section====================================================</p><br>';
		}
		if($type=='Section Text'){
			echo '<p align="center">'.$question.'</p><br>';
			$num--;
		}elseif($type =='Text'){
			if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			echo '<input type="text" size = "50px"><br>';
		}elseif($type=='Date'||$type=='Numeric'){
			if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			echo '<input type="text" size = "15px"><br>';
		}elseif($type=='Yes/No'){
		    if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			echo '<input type="radio">Yes<br>';
			echo '<input type="radio">No<br>';
		}elseif($type=='Check Box'){
			if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			
			if($response1!='')
			echo '<input type="checkbox">'.$response1.'<br>';
			if($response2!='')
			echo '<input type="checkbox">'.$response2.'<br>';
			if($response3!='')
			echo '<input type="checkbox">'.$response3.'<br>';
			if($response4!='')
			echo '<input type="checkbox">'.$response4.'<br>';
			if($response5!='')
			echo '<input type="checkbox">'.$response5.'<br>';
			if($response6!='')
			echo '<input type="checkbox">'.$response6.'<br>';
		}elseif($type=='Radio Button'){
			if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			
			if($response1!='')
			echo '<input type="radio">'.$response1.'<br>';
			if($response2!='')
			echo '<input type="radio">'.$response2.'<br>';
			if($response3!='')
			echo '<input type="radio">'.$response3.'<br>';
			if($response4!='')
			echo '<input type="radio">'.$response4.'<br>';
			if($response5!='')
			echo '<input type="radio">'.$response5.'<br>';
			if($response6!='')
			echo '<input type="radio">'.$response6.'<br>';
		}elseif($type=='Drop Down'){
			if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			echo'<select>';
			if($response1!='')
			echo '<option>'.$response1.'</option>';
			if($response2!='')
			echo '<option>'.$response2.'</option>';
			if($response3!='')
			echo '<option>'.$response3.'</option>';
			if($response4!='')
			echo '<option>'.$response4.'</option>';
			if($response5!='')
			echo '<option>'.$response5.'</option>';
			if($response6!='')
			echo '<option>'.$response6.'</option>';
			echo '</select><br>';
		}elseif($type=='Rate'){
			if($required=='Y')
			echo '<font color="red" size="5">*</font>';
			echo '<b>'.$num.'. '.$question.'</b><br>';
			echo '<table>';
			
			echo '<tr><td width="70px">Value</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>';
			if($response1!='')
			echo '<tr><td width="70px">'.$response1.'</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
            if($response2!='')
			echo '<tr><td width="70px">'.$response2.'</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
			if($response3!='')
			echo '<tr><td width="70px">'.$response3.'</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
			if($response4!='')
			echo '<tr><td width="70px">'.$response4.'</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
			if($response5!='')
			echo '<tr><td width="70px">'.$response5.'</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
			if($response6!='')
			echo '<tr><td width="70px">'.$response6.'</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
		   echo '</table><br>';
		}
	echo'<br>';
	$num++;
	}
	if($size==$i+1){
	if($sec>2){
			echo "<div id='back'><input type='button' onclick='history.go(-1)' Value='Back'></div>";
			}
		echo '<div id="next"><input type="submit" value="Submit Survey"></div>';
	}
	}
}

?>
</div><br>
<a href='question.php?sid=<?php echo $survey_id;?>'>Go Back to Questions</a>
<div class='clear'></div>
<?php 
require_once '../../footer.php';
?>